package com.wontube.smr.remote.web;

import java.util.List;

import com.wontube.client.extension.utils.StringUtils;
import com.wontube.client.modle.vo.PagenateInfo;
import com.wontube.core.annotation.CacheSupport;
import com.wontube.core.annotation.NoLoginSupport;
import com.wontube.core.pub.servlet.handlers.BasicHandler;
import com.wontube.smr.bo.sites.GenreSelectBO;
import com.wontube.smr.client.model.po.Genre;
import com.wontube.smr.client.model.po.TVEpisode;
import com.wontube.smr.client.model.po.TVShow;
import com.wontube.smr.client.model.vo.SeasonEpisodes;
import com.wontube.smr.client.model.vo.TVShowItems;
import com.wontube.smr.dao.bo.TVSelectDao;
import com.wontube.smr.web.client.ITVWebHandler;
import com.wontube.smr.web.client.model.bo.QueryItemParams;

/**
 * @author tanggf(2012-7-26)
 *
 */
@NoLoginSupport
public final class TVWebHandler extends BasicHandler implements ITVWebHandler {
	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 7 * 3600)
	public List<Genre> listTVGenres() {
		return GenreSelectBO.selectRemendedTVGenres();
	}
	
	
	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVShowItems listHuluTVShows(QueryItemParams params, PagenateInfo pageInfo) {
		params.setGenre(GenreSelectBO.joinTVGenres(params.getGenre()));
		TVShowItems items = TVSelectDao.selectHuluTVShows(params, pageInfo);
		//判断是否需要genre
		if(params.isNeedGenres()){
			items.setTvGenres(listTVGenres());
		}
		
		return items;
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVShow getTVShow(String showId) {
		if(StringUtils.isNullOrEmpty(showId)){
			return null;
		}
		return TVSelectDao.getTVShow(showId);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVEpisode getTVEpisode(String epId) {
		if(StringUtils.isNullOrEmpty(epId)){
			return null;
		}
		return TVSelectDao.getTVEpisode(epId);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public List<SeasonEpisodes> listTVEpisodeDetail(String showId) {
		if(StringUtils.isNullOrEmpty(showId)){
			return null;
		}
		return TVSelectDao.getAllEpisodes(showId);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 2 * 3600)
	public TVShowItems listChineseTVShows(PagenateInfo pageInfo) {
		return TVSelectDao.selectCrunchyrollCountryDramas(TVShow.CATEGORY_CHINESE_TV, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 2 * 3600)
	public TVShowItems listJapaneseTVShows(PagenateInfo pageInfo) {
		return TVSelectDao.selectCrunchyrollCountryDramas(TVShow.CATEGORY_JAPANESE_TV, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 2 * 3600)
	public TVShowItems listKoreaTVShows(PagenateInfo pageInfo) {
		return TVSelectDao.selectCrunchyrollCountryDramas(TVShow.CATEGORY_KOREAN_TV, pageInfo);
	}
	
	@Override
	@CacheSupport(timeToLiveSeconds = 2 * 3600)
	public TVShowItems listSurpriseDramaTVShows(PagenateInfo pageInfo){			
		return TVSelectDao.selectCrunchyrollDramas(pageInfo);
	}
}
